import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

/**
 * 广告
 */

const useAd = defineStore(
  'ad',
  () => {
    
    const adList = ref([])
    const setAdList = (val)=>{
      adList.value = val
    }

    const getAd = computed(() => {
      return (position, key) => {
        const f = adList.value.find((item) => item.position === position)
        return f ? f[key] : null
      }
    })

    return {
      setAdList,
      getAd
    }
  },
  {
    persist: {
      enabled: false,
      strategies: [
        {
          storage: localStorage
        }
      ]
    }
  }
)

export default useAd
